//
//  HouseManagerViewController.m
//  YaDiuDiu
//
//  Created by 欧洪飞 on 2017/10/10.
//  Copyright © 2017年 jy. All rights reserved.
//

#import "HouseManagerViewController.h"

#import "HouseMagerView.h"
#import "HouseImagesViewController.h"
#import "MapSelPlaceViewController.h"
@interface HouseManagerViewController ()<UIImagePickerControllerDelegate,UINavigationControllerDelegate,UIPickerViewDelegate,UIPickerViewDataSource,MapSelPlaceViewControllerDelegate,HouseImagesViewControllerDelegate,UITextFieldDelegate>{
    HouseMagerView *view;
    UIImagePickerController *imagepc;
    NSArray *arrZX;//装修数据源
    NSArray *arrCX;//朝向数据源
    NSMutableArray *arrYear;//建于年代数据源
    NSArray *arrYT;//用途数据源
    NSArray *arrStyle;//建筑类型数据源
    
    NSMutableArray *arrayLab;//标签
    UIScrollView *sclView;//
}

@property (nonatomic,strong)UIPickerView *pickerView1;
@property (nonatomic,strong)UIPickerView *pickerView2;
@property (nonatomic,strong)UIPickerView *pickerView3;
@property (nonatomic,strong)UIPickerView *pickerView4;
@property (nonatomic,strong)UIPickerView *pickerView5;
@property (nonatomic,strong)UIPickerView *pickerView6;

@property (nonatomic,strong)UIView *view1;
@property (nonatomic,strong)UIView *view2;
@property (nonatomic,strong)UIView *view3;
@property (nonatomic,strong)UIView *view4;
@property (nonatomic,strong)UIView *view5;
@property (nonatomic,strong)UIView *view6;

@property (nonatomic,strong)NSMutableArray *array1;//面积
@property (nonatomic,copy)NSString *str1;
@property (nonatomic,copy)NSString *str2;

@property (nonatomic,strong)NSMutableArray *arrayImages;//图片数组
@property (nonatomic,strong)NSMutableArray *arrimgUr;//图片地址
@property (nonatomic,copy)NSString *ImageUrl;//图片路径

@property (nonatomic,copy)NSString *lat;
@property (nonatomic,copy)NSString *lng;

@property (nonatomic,strong)NSDictionary *dic;//楼盘资料数据源

@end

@implementation HouseManagerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.view.backgroundColor = COLOR_RGB(242, 242, 242, 1);
    arrYear = [NSMutableArray array];
    _array1 = [NSMutableArray array];
    arrayLab = [NSMutableArray array];
    _arrayImages = [NSMutableArray array];
    _arrimgUr = [NSMutableArray array];
    for (NSInteger i = 2010; i<=2020; i++) {
        NSString *str = [NSString stringWithFormat:@"%li",i];
        [arrYear addObject:str];
    }
    
    for (NSInteger i = 1; i<=500; i++) {
        NSString *str = [NSString stringWithFormat:@"%li",i];
        [_array1 addObject:str];
    }
    arrZX = @[@"毛坯",@"简装",@"中装",@"精装"];
    arrCX = @[@"东",@"南",@"西",@"北",@"东南",@"东北",@"西北",@"东西",@"南北"];
    arrYT = @[@"住房",@"商房",@"办公楼",@"商铺"];
    arrStyle = @[@"高层",@"中层",@"低层"];
    if ([_state isEqualToString:@"aaa"]) {//查看详情
        [self showNav:@"商品详情"];
        [self loadData2];
        UIScrollView *scl = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 64, ScreenWidth, ScreenHeight-64)];
        scl.contentSize = CGSizeMake(ScreenWidth, 1040);
        scl.bounces = NO;
        [self.view addSubview:scl];
        
        view = [[[NSBundle mainBundle] loadNibNamed:@"HouseMagerView" owner:nil options:nil] lastObject];
        view.frame = CGRectMake(0, 0, ScreenWidth, 1040);
        [scl addSubview:view];
        
        sclView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 170)];
        sclView.hidden = YES;
        sclView.pagingEnabled = YES;
        [view.images addSubview:sclView];
        
    }else if ([_state isEqualToString:@"sss"]){//修改
        [self showNav:@"修改商品"];
        [self loadData2];
        UIScrollView *scl = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 64, ScreenWidth, ScreenHeight-64)];
        scl.contentSize = CGSizeMake(ScreenWidth, 1100);
        [self.view addSubview:scl];
        
        view = [[[NSBundle mainBundle] loadNibNamed:@"HouseMagerView" owner:nil options:nil] lastObject];
        view.frame = CGRectMake(0, 0, ScreenWidth, 1100);
        [scl addSubview:view];
        
        sclView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 170)];
        sclView.hidden = YES;
        sclView.pagingEnabled = YES;
        [view.images addSubview:sclView];
        
    }else {
        [self showNav:@"添加楼盘"];
        UIScrollView *scl = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 64, ScreenWidth, ScreenHeight-64)];
        scl.contentSize = CGSizeMake(ScreenWidth, 1100);
        [self.view addSubview:scl];
        
        view = [[[NSBundle mainBundle] loadNibNamed:@"HouseMagerView" owner:nil options:nil] lastObject];
        view.frame = CGRectMake(0, 0, ScreenWidth, 1100);
        [scl addSubview:view];
        
        sclView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 170)];
        sclView.hidden = YES;
        sclView.pagingEnabled = YES;
        [view.images addSubview:sclView];
        
    }
    
    [self loadUI];
}


- (void)loadUI{
    
    view.images.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(click1)];
    [view.images addGestureRecognizer:tap1];
    
    view.lab1.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(click2)];
    [view.lab1 addGestureRecognizer:tap2];
    //装修
    view.lab2.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap3 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(click3)];
    [view.lab2 addGestureRecognizer:tap3];
    //朝向
    view.lab3.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap4 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(click4)];
    [view.lab3 addGestureRecognizer:tap4];
    //建于
    view.lab4.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap5 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(click5)];
    [view.lab4 addGestureRecognizer:tap5];
    //装修用途
    view.lab5.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap6 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(click6)];
    [view.lab5 addGestureRecognizer:tap6];
    
    view.lab6.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap7 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(click7)];
    [view.lab6 addGestureRecognizer:tap7];
    
    view.lab7.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap8 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(click8)];
    [view.lab7 addGestureRecognizer:tap8];
    
    view.text9.delegate = self;
    
    [view.btnaddLab addTarget:self action:@selector(clickAddLab) forControlEvents:UIControlEventTouchUpInside];
    [view.btnAdd addTarget:self action:@selector(clickAdd) forControlEvents:UIControlEventTouchUpInside];
    
    [view.btnClear addTarget:self action:@selector(clickClear) forControlEvents:UIControlEventTouchUpInside];
    view.scrollView.contentSize = CGSizeMake(500, 30);
    
}
//删除标签
- (void)clickClear{
    arrayLab = [NSMutableArray array];
    view.scrollView.hidden = YES;
}

-(void)textFieldDidEndEditing:(UITextField *)textField{
    if (textField.text.length > 5) {
        
    }else{
        view.text9.text = textField.text;
    }
}
//添加标签
- (void)clickAddLab{
    if (view.text9.text.length == 0) {
        [self showAlert:@"请输入标签"];
        return;
    }
    view.scrollView.hidden = NO;
    //添加数据
    NSString *str = view.text9.text;
    [arrayLab addObject:str];
    
    for (NSInteger i = 0; i < arrayLab.count; i++) {
        UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(10*(i+1)+80*i, 0, 80, 30)];
        lab.text = arrayLab[i];
        lab.textAlignment = NSTextAlignmentCenter;
        lab.textColor = [UIColor whiteColor];
        lab.backgroundColor = [UIColor lightGrayColor];
        lab.font = [UIFont systemFontOfSize:15.0];
        lab.layer.cornerRadius = 10.0;
        [view.scrollView addSubview:lab];
    }
    
    view.text9.text = @"";
}
//图片
- (void)click1{
    HouseImagesViewController *images = [[HouseImagesViewController alloc] init];
    images.delegate = self;
    images.images = _arrayImages;
    images.arrayImgUrl = _arrimgUr;
    [self.navigationController pushViewController:images animated:YES];
}

- (void)click2{
    MapSelPlaceViewController *map = [[MapSelPlaceViewController alloc] init];
    map.delegate = self;
    [self.navigationController pushViewController:map animated:YES];
    
}
#pragma -mark MapSelPlaceViewControllerDelegate
-(void)sendText:(NSString *)text Province:(NSString *)proce City:(NSString *)city Area:(NSString *)area{
    view.lab1.text = text;
}

-(void)sendLat:(NSString *)lat sendLng:(NSString *)lng{
    _lat = lat;
    _lng = lng;
}

-(void)sendAddress:(NSString *)address Det:(NSString *)det{
    
}

-(void)sendImgUrl:(NSMutableArray *)imgUrl{
    _arrimgUr = imgUrl;
    _ImageUrl = [imgUrl componentsJoinedByString:@"|"];
    for (NSString *str in imgUrl) {
        NSString *aaa = [NSString stringWithFormat:@"%@%@",[user objectForKey:@"ImageUrl"],str];
        [_arrayImages addObject:aaa];
    }
    view.image1.hidden = YES;
    view.labSC.hidden = YES;
    view.labZS.hidden = YES;
    sclView.hidden = NO;
    sclView.contentSize = CGSizeMake(ScreenWidth, 170);
    for (NSInteger i = 0; i<_arrayImages.count; i++) {
        UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(0, ScreenWidth*i, ScreenWidth, 170)];
        [image sd_setImageWithURL:[NSURL URLWithString:_arrayImages[i]] placeholderImage:nil];
        [sclView addSubview:image];
        
    }
    
    NSLog(@"imageUrl:%@",_ImageUrl);
}

- (void)click3{
    _view1 = [[UIView alloc] initWithFrame:CGRectMake(0, ScreenHeight-200, ScreenWidth, 200)];
    _view1.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.view addSubview:_view1];
    
    UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
    btn1.frame = CGRectMake(16, 0, 60, 40);
    [btn1 setTitle:@"取消" forState:UIControlStateNormal];
    [btn1 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [btn1 addTarget:self action:@selector(clickCancel) forControlEvents:UIControlEventTouchUpInside];
    [_view1 addSubview:btn1];
    
    UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
    btn2.frame = CGRectMake(ScreenWidth-76, 0, 60, 40);
    [btn2 setTitle:@"确定" forState:UIControlStateNormal];
    [btn2 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [btn2 addTarget:self action:@selector(clickSure) forControlEvents:UIControlEventTouchUpInside];
    [_view1 addSubview:btn2];
    
    _pickerView1 = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 40, ScreenWidth, 160)];
    _pickerView1.backgroundColor = [UIColor whiteColor];
    _pickerView1.delegate = self;
    _pickerView1.dataSource = self;
    [_view1 addSubview:_pickerView1];
    
}

- (void)clickCancel{
    [_view1 removeFromSuperview];
    [_view2 removeFromSuperview];
    [_view3 removeFromSuperview];
    [_view4 removeFromSuperview];
    [_view5 removeFromSuperview];
    [_view6 removeFromSuperview];
}

- (void)clickSure{
    [_view1 removeFromSuperview];
    [_view2 removeFromSuperview];
    [_view3 removeFromSuperview];
    [_view4 removeFromSuperview];
    [_view5 removeFromSuperview];
    [_view6 removeFromSuperview];
    
}

- (void)click4{
    _view2 = [[UIView alloc] initWithFrame:CGRectMake(0, ScreenHeight-200, ScreenWidth, 200)];
    _view2.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.view addSubview:_view2];
    
    UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
    btn1.frame = CGRectMake(16, 0, 60, 40);
    [btn1 setTitle:@"取消" forState:UIControlStateNormal];
    [btn1 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [btn1 addTarget:self action:@selector(clickCancel) forControlEvents:UIControlEventTouchUpInside];
    [_view2 addSubview:btn1];
    
    UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
    btn2.frame = CGRectMake(ScreenWidth-76, 0, 60, 40);
    [btn2 setTitle:@"确定" forState:UIControlStateNormal];
    [btn2 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [btn2 addTarget:self action:@selector(clickSure) forControlEvents:UIControlEventTouchUpInside];
    [_view2 addSubview:btn2];
    
    _pickerView2 = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 40, ScreenWidth, 160)];
    _pickerView2.backgroundColor = [UIColor whiteColor];
    _pickerView2.delegate = self;
    _pickerView2.dataSource = self;
    [_view2 addSubview:_pickerView2];
}

- (void)click5{
    _view3 = [[UIView alloc] initWithFrame:CGRectMake(0, ScreenHeight-200, ScreenWidth, 200)];
    _view3.backgroundColor = [UIColor groupTableViewBackgroundColor];;
    [self.view addSubview:_view3];
    
    UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
    btn1.frame = CGRectMake(16, 0, 60, 40);
    [btn1 setTitle:@"取消" forState:UIControlStateNormal];
    [btn1 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [btn1 addTarget:self action:@selector(clickCancel) forControlEvents:UIControlEventTouchUpInside];
    [_view3 addSubview:btn1];
    
    UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
    btn2.frame = CGRectMake(ScreenWidth-76, 0, 60, 40);
    [btn2 setTitle:@"确定" forState:UIControlStateNormal];
    [btn2 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [btn2 addTarget:self action:@selector(clickSure) forControlEvents:UIControlEventTouchUpInside];
    [_view3 addSubview:btn2];
    
    _pickerView3 = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 40, ScreenWidth, 160)];
    _pickerView3.backgroundColor = [UIColor whiteColor];
    _pickerView3.delegate = self;
    _pickerView3.dataSource = self;
    [_view3 addSubview:_pickerView3];
}

- (void)click6{
    _view4 = [[UIView alloc] initWithFrame:CGRectMake(0, ScreenHeight-200, ScreenWidth, 200)];
    _view4.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.view addSubview:_view4];
    
    UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
    btn1.frame = CGRectMake(16, 0, 60, 40);
    [btn1 setTitle:@"取消" forState:UIControlStateNormal];
    [btn1 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [btn1 addTarget:self action:@selector(clickCancel) forControlEvents:UIControlEventTouchUpInside];
    [_view4 addSubview:btn1];
    
    UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
    btn2.frame = CGRectMake(ScreenWidth-76, 0, 60, 40);
    [btn2 setTitle:@"确定" forState:UIControlStateNormal];
    [btn2 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [btn2 addTarget:self action:@selector(clickSure) forControlEvents:UIControlEventTouchUpInside];
    [_view4 addSubview:btn2];
    
    _pickerView4 = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 40, ScreenWidth, 160)];
    _pickerView4.backgroundColor = [UIColor whiteColor];
    _pickerView4.delegate = self;
    _pickerView4.dataSource = self;
    [_view4 addSubview:_pickerView4];
}

- (void)click7{
    _view5 = [[UIView alloc] initWithFrame:CGRectMake(0, ScreenHeight-200, ScreenWidth, 200)];
    _view5.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.view addSubview:_view5];
    
    UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
    btn1.frame = CGRectMake(16, 0, 60, 40);
    [btn1 setTitle:@"取消" forState:UIControlStateNormal];
    [btn1 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [btn1 addTarget:self action:@selector(clickCancel) forControlEvents:UIControlEventTouchUpInside];
    [_view5 addSubview:btn1];
    
    UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
    btn2.frame = CGRectMake(ScreenWidth-76, 0, 60, 40);
    [btn2 setTitle:@"确定" forState:UIControlStateNormal];
    [btn2 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [btn2 addTarget:self action:@selector(clickSure) forControlEvents:UIControlEventTouchUpInside];
    [_view5 addSubview:btn2];
    
    _pickerView5 = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 40, ScreenWidth, 160)];
    _pickerView5.backgroundColor = [UIColor whiteColor];
    _pickerView5.delegate = self;
    _pickerView5.dataSource = self;
    [_view5 addSubview:_pickerView5];
}

- (void)click8{
    _view6 = [[UIView alloc] initWithFrame:CGRectMake(0, ScreenHeight-200, ScreenWidth, 200)];
    _view6.backgroundColor = [UIColor groupTableViewBackgroundColor];;
    [self.view addSubview:_view6];
    
    UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
    btn1.frame = CGRectMake(16, 0, 60, 40);
    [btn1 setTitle:@"取消" forState:UIControlStateNormal];
    [btn1 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [btn1 addTarget:self action:@selector(clickCancel) forControlEvents:UIControlEventTouchUpInside];
    [_view6 addSubview:btn1];
    
    UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
    btn2.frame = CGRectMake(ScreenWidth-76, 0, 60, 40);
    [btn2 setTitle:@"确定" forState:UIControlStateNormal];
    [btn2 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [btn2 addTarget:self action:@selector(clickSure) forControlEvents:UIControlEventTouchUpInside];
    [_view6 addSubview:btn2];
    
    _pickerView6 = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 40, ScreenWidth, 160)];
    _pickerView6.backgroundColor = [UIColor whiteColor];
    _pickerView6.delegate = self;
    _pickerView6.dataSource = self;
    [_view6 addSubview:_pickerView6];
}

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    if (pickerView == _pickerView6) {
        return 2;
    }
    return 1;
}

-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    if (pickerView == _pickerView1) {
        return arrZX.count;
    }else if (pickerView == _pickerView2){
        return arrCX.count;
    }else if (pickerView == _pickerView3){
        return arrYear.count;
    }else if (pickerView == _pickerView4){
        return arrYT.count;
    }else if (pickerView == _pickerView5){
        return arrStyle.count;
    }else if (pickerView == _pickerView6){
        return _array1.count;
    }else{
        return 0;
    }
}

-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    if (pickerView == _pickerView1) {
        NSString *str = arrZX[row];
        return str;
    }else if (pickerView == _pickerView2){
        NSString *str = arrCX[row];
        return str;
    }else if (pickerView == _pickerView3){
        NSString *str = arrYear[row];
        return str;
    }else if (pickerView == _pickerView4){
        NSString *str = arrYT[row];
        return str;
    }else if (pickerView == _pickerView5){
        NSString *str = arrStyle[row];
        return str;
    }else if (pickerView == _pickerView6){
        return _array1[row];
    }else{
        
        return @"aaaa";
        
    }
}

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    if (pickerView == _pickerView1) {
        NSString *str = arrZX[row];
        view.lab2.text = str;
    }else if (pickerView == _pickerView2){
        view.lab3.text = arrCX[row];
    }else if (pickerView == _pickerView3){
        view.lab4.text = arrYear[row];
    }else if (pickerView == _pickerView4){
        view.lab5.text = arrYT[row];
    }else if (pickerView == _pickerView5){
        view.lab6.text = arrStyle[row];
    }else if (pickerView == _pickerView6){
        if (component == 0) {
            _str1 = _array1[row];
        }else{
            _str2 = _array1[row];
        }
        if ([_str1 integerValue] < [_str2 integerValue]) {
           view.lab7.text = [NSString stringWithFormat:@"%@-%@",_str1,_str2];
        }
        
    }
    
}
//添加按钮
- (void)clickAdd{
    if ([_state isEqualToString:@"sss"]) {//修改
        [self upDateHouse];
    }else{
        [self AddHouse];
    }
    
}
//修改新房
- (void)upDateHouse{
    [SVProgressHUD show];
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
    NSString *str = [NSString stringWithFormat:@"%@890d69e502d1d37a9e84335ccefece57",[user objectForKey:@"token2"]];
    NSString *token = [LCMD5Tool md5:str];
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    [parmas setObject:_houseid forKey:@"id"];
    [parmas setObject:[user objectForKey:@"userid"] forKey:@"userid"];
    [parmas setObject:token forKey:@"verifiToken"];
    
    if (_ImageUrl.length > 0) {
        [parmas setObject:_ImageUrl forKey:@"pics"];
    }else{
        [parmas setObject:[_dic objectForKey:@"homepic"] forKey:@"pics"];
    }
    [parmas setObject:_merid forKey:@"merids"];
    [parmas setObject:view.text1.text forKey:@"titles"];
    [parmas setObject:view.lab5.text forKey:@"types"];
    [parmas setObject:view.text2.text forKey:@"prices"];
    [parmas setObject:view.lab2.text forKey:@"fitmentfinishs"];
    [parmas setObject:view.lab3.text forKey:@"orientations"];
    [parmas setObject:view.text3.text forKey:@"profiles"];
    [parmas setObject:view.lab1.text forKey:@"addresss"];
    [parmas setObject:view.lab4.text forKey:@"quotationtimes"];
    [parmas setObject:view.text4.text forKey:@"otherstimes"];
    [parmas setObject:view.lab6.text forKey:@"cturetypes"];
    [parmas setObject:view.text5.text forKey:@"layouts"];
    NSString *aaa = [arrayLab componentsJoinedByString:@"|"];
    [parmas setObject:aaa forKey:@"labellings"];
    [parmas setObject:view.text6.text forKey:@"greeningrates"];
    [parmas setObject:view.text7.text forKey:@"carport"];
    [parmas setObject:view.text8.text forKey:@"plotratio"];
    [parmas setObject:view.lab7.text forKey:@"qujian"];
    if (_lat.length > 0) {
        [parmas setObject:_lng forKey:@"longitude"];
        [parmas setObject:_lat forKey:@"latitude"];
    }else{
        [parmas setObject:[_dic objectForKey:@"longitude"] forKey:@"longitude"];
        [parmas setObject:[_dic objectForKey:@"latitude"] forKey:@"latitude"];
    }
    
    NSLog(@"parmas:%@",parmas);
    NSString *url = [NSString stringWithFormat:@"%@/App/Bridalchamber/edithomel",urlHead];
    [[AFHTTPSessionManager manager] POST:url parameters:parmas success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"修改楼盘res:%@",responseObject);
        NSString *error = [NSString stringWithFormat:@"%li",[[responseObject objectForKey:@"error"] integerValue]];
        if ([error integerValue] == 200) {
            [self.navigationController popViewControllerAnimated:YES];
        }
        [SVProgressHUD dismiss];
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"error:%@",error);
        [SVProgressHUD dismiss];
    }];
}

//添加楼盘
- (void)AddHouse{
    
    if (_ImageUrl.length == 0) {
        [self showAlert:@"请选择图片"];
        return;
    }else if (view.text1.text.length == 0){
        [self showAlert:@"请输入楼盘名称"];
        return;
    }else if (view.text2.text.length == 0){
        [self showAlert:@"请输入价格"];
        return;
    }else if (view.text3.text.length == 0){
        [self showAlert:@"请输入户数"];
        return;
    }else if (view.text4.text.length == 0){
        [self showAlert:@"请输入年限"];
        return;
    }else if (view.text5.text.length == 0){
        [self showAlert:@"请输入物业公司"];
        return;
    }else if (view.text6.text.length == 0){
        [self showAlert:@"请填写绿化率"];
        return;
    }else if (view.text7.text.length == 0){
        [self showAlert:@"请输入车位配比"];
        return;
    }else if (view.text8.text.length == 0){
        [self showAlert:@"请输入容积率"];
        return;
    }else if (view.text9.text.length == 0){
        [self showAlert:@"请添加标签"];
        return;
    }else if ([view.lab1.text isEqualToString:@"请选择"]){
        [self showAlert:@"请选择地址"];
        return;
    }else if ([view.lab2.text isEqualToString:@"请选择"]){
        [self showAlert:@"请选择装修类型"];
        return;
    }else if ([view.lab3.text isEqualToString:@"请选择"]){
        [self showAlert:@"请选择朝向"];
        return;
    }else if ([view.lab4.text isEqualToString:@"请选择"]){
        [self showAlert:@"请选择建于时间"];
        return;
    }else if ([view.lab5.text isEqualToString:@"请选择"]){
        [self showAlert:@"请选择用途"];
        return;
    }else if ([view.lab6.text isEqualToString:@"请选择"]){
        [self showAlert:@"请选择建筑类型"];
        return;
    }else if ([view.lab7.text isEqualToString:@"请选择"]){
        [self showAlert:@"请选择区间面积"];
        return;
    }
    
    [SVProgressHUD show];
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
    NSString *str = [NSString stringWithFormat:@"%@890d69e502d1d37a9e84335ccefece57",[user objectForKey:@"token2"]];
    NSString *token = [LCMD5Tool md5:str];
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    [parmas setObject:_ImageUrl forKey:@"pics"];
    [parmas setObject:_merid forKey:@"merids"];
    [parmas setObject:view.text1.text forKey:@"titles"];
    [parmas setObject:view.lab5.text forKey:@"types"];
    [parmas setObject:view.text2.text forKey:@"prices"];
    [parmas setObject:view.lab2.text forKey:@"fitmentfinishs"];
    
    [parmas setObject:view.lab3.text forKey:@"orientations"];
    [parmas setObject:view.text3.text forKey:@"profiles"];
    [parmas setObject:view.lab1.text forKey:@"addresss"];
    [parmas setObject:view.lab4.text forKey:@"quotationtimes"];
    [parmas setObject:view.text4.text forKey:@"otherstimes"];
    [parmas setObject:view.lab6.text forKey:@"cturetypes"];
    [parmas setObject:view.text5.text forKey:@"layouts"];
    NSString *aaa = [arrayLab componentsJoinedByString:@"|"];
    [parmas setObject:aaa forKey:@"labellings"];
    [parmas setObject:view.text6.text forKey:@"greeningrates"];
    
    [parmas setObject:token forKey:@"verifiToken"];
    [parmas setObject:view.text7.text forKey:@"carport"];
    [parmas setObject:view.text8.text forKey:@"plotratio"];
    [parmas setObject:view.lab7.text forKey:@"qujian"];
    [parmas setObject:[user objectForKey:@"userid"] forKey:@"userid"];
    [parmas setObject:_lng forKey:@"longitude"];
    [parmas setObject:_lat forKey:@"latitude"];
    NSLog(@"parmas:%@",parmas);
    NSString *url = [NSString stringWithFormat:@"%@/App/Bridalchamber/rental",urlHead];
    [[AFHTTPSessionManager manager] POST:url parameters:parmas success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"发布楼盘res:%@",responseObject);
        NSString *error = [NSString stringWithFormat:@"%li",[[responseObject objectForKey:@"error"] integerValue]];
        if ([error integerValue] == 200) {
            [self.navigationController popViewControllerAnimated:YES];
        }
        [SVProgressHUD dismiss];
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"error:%@",error);
        [SVProgressHUD dismiss];
    }];
}
//商家中心新房详情
- (void)loadData2{
    [SVProgressHUD show];
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    [parmas setObject:_houseid forKey:@"houseid"];
    NSString *url = [NSString stringWithFormat:@"%@/App/Bridalchamber/houesingdatails",urlHead];
    [[AFHTTPSessionManager manager] POST:url parameters:parmas success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"新房详情res:%@",responseObject);
        NSString *error = [NSString stringWithFormat:@"%li",[[responseObject objectForKey:@"error"] integerValue]];
        if ([error integerValue] == 200) {
            _dic = [responseObject objectForKey:@"result"];
            [self loadUI2];
        }
        [SVProgressHUD dismiss];
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"error:%@",error);
        [SVProgressHUD dismiss];
    }];
    
}

- (void)loadUI2{
    if ([_state isEqualToString:@"aaa"]) {//查看
        view.text1.enabled = NO;
        view.text2.enabled = NO;
        view.text3.enabled = NO;
        view.text4.enabled = NO;
        view.text5.enabled = NO;
        view.text6.enabled = NO;
        view.text7.enabled = NO;
        view.text8.enabled = NO;
        view.text9.enabled = NO;
        
        view.lab1.userInteractionEnabled = NO;
        view.lab2.userInteractionEnabled = NO;
        view.lab3.userInteractionEnabled = NO;
        view.lab4.userInteractionEnabled = NO;
        view.lab5.userInteractionEnabled = NO;
        view.lab6.userInteractionEnabled = NO;
        view.lab7.userInteractionEnabled = NO;
        view.btnClear.userInteractionEnabled = NO;
        view.btnaddLab.userInteractionEnabled = NO;
        
    }else{
        [view.btnAdd setTitle:@"修改" forState:UIControlStateNormal];
    }
    //
    NSString *homepic = [_dic objectForKey:@"homepic"];
    NSArray *imgurl = [homepic componentsSeparatedByString:@"|"];
    NSMutableArray *arrImg = [NSMutableArray array];
    for (NSString *str in imgurl) {
        NSString *aaa = [NSString stringWithFormat:@"%@%@",[user objectForKey:@"ImageUrl"],str];
        [arrImg addObject:aaa];
    }
    view.image1.hidden = YES;
    view.labSC.hidden = YES;
    view.labZS.hidden = YES;
    
    UIView *v = [WTImageScroll ShowNetWorkImageScrollWithFream:CGRectMake(0, 0, ScreenWidth, 170) andImageArray:arrImg andBtnClick:^(NSInteger tagValue) {
        if ([_state isEqualToString:@"sss"]) {
            HouseImagesViewController *images = [[HouseImagesViewController alloc] init];
            images.images = arrImg;
            [self.navigationController pushViewController:images animated:YES];
        }
    }];
    [view.images addSubview:v];
    
    view.text1.text = [_dic objectForKey:@"title"];
    view.text2.text = [_dic objectForKey:@"price"];
    view.text3.text = [_dic objectForKey:@"profile"];
    view.text4.text = [_dic objectForKey:@"otherstime"];
    view.text5.text = [_dic objectForKey:@"layout"];
    view.text6.text = [_dic objectForKey:@"greeningrate"];
    view.text7.text = [_dic objectForKey:@"carport"];
    view.text8.text = [_dic objectForKey:@"plotratio"];
    NSString *labelline = [_dic objectForKey:@"labelling"];
    NSArray *arr = [labelline componentsSeparatedByString:@"|"];
    arrayLab = [NSMutableArray arrayWithArray:arr];
    for (NSInteger i = 0; i < arrayLab.count; i++) {
        UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(10*(i+1)+80*i, 0, 80, 30)];
        lab.text = arrayLab[i];
        lab.textAlignment = NSTextAlignmentCenter;
        lab.textColor = [UIColor whiteColor];
        lab.backgroundColor = [UIColor lightGrayColor];
        lab.font = [UIFont systemFontOfSize:15.0];
        lab.layer.cornerRadius = 10.0;
        [view.scrollView addSubview:lab];
    }
    
    view.lab1.text = [_dic objectForKey:@"address"];
    view.lab2.text = [_dic objectForKey:@"fitmentfinish"];
    view.lab3.text = [_dic objectForKey:@"orientation"];
    view.lab4.text = [_dic objectForKey:@"quotationtime"];
    view.lab5.text = [_dic objectForKey:@"type"];
    view.lab6.text = [_dic objectForKey:@"cturetype"];
    view.lab7.text = [_dic objectForKey:@"qujian"];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
